package niso;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;


import panels.*;

public class userFrame extends JFrame implements WindowListener{

	private User CurrentUser;
	private JTabbedPane tab;
	private DBHandler DBHelp;
	private ImageIcon check,Exclaim;
	private Font Warning;
	
	public userFrame(User u,DBHandler handler){
		super("NiSoft");
		CurrentUser=u;
		DBHelp=handler;
		tab=new JTabbedPane();
		check=new ImageIcon("Images/check.png");
		Exclaim=new ImageIcon("Images/exclaim.png");
		Warning=new Font("Arial", Font.BOLD, 12);
		
		tab.add("test User",new ManageUser(this));
		tab.add("test Inventory",new InventoryPane(this));
		tab.add("test Expense",new ExpensePane(this));
		tab.add("test Sales",new SalesPane(this));
		
		
		System.out.println("parent type: "+u.getusertype());
		add(tab);
		pack();
		setVisible(true);
		addWindowListener(this);
		
		
	}

	/*
	 * 	+generateUIComponents(String):String
		+actionPerformed(ActionEvent):void
	 */
	public DBHandler getDBHandler(){return DBHelp;}
	public ImageIcon getCheckImage(){return check;}
	public ImageIcon getExclaimImage(){return Exclaim;}
	public User getUser(){return CurrentUser;}
	public Font getWarningFont(Component C){
		C.setForeground(Color.RED);
		return Warning;
	}
	
	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		if(DBHelp!=null)
			DBHelp.CloseConnection();
		System.out.println(" Close ");
		System.exit(0);
		
	}

	@Override
	public void windowClosing(WindowEvent e) {
		if(DBHelp!=null)
			DBHelp.CloseConnection();
		System.out.println(" Close ");
		System.exit(0);
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}
}
